package com.chaofan.authsso.core.web;

import cn.hutool.core.util.StrUtil;
import com.chaofan.authsso.core.common.Constant;
import com.chaofan.authsso.core.common.Methods;
import com.chaofan.authsso.core.common.SsoRestfulMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Author: Chaofan
 * Date: 2020/6/11 17:06
 * email: chaofan2685@qq.com
 */
@RequestMapping(value = "/authsso/error")
public class ErrorController extends Methods {

    @Autowired
    HttpSession session;

    @GetMapping(value = "/getErrorMsg")
    @ResponseBody
    public SsoRestfulMessage<String> getErrorMsg(){
        String errorMsg = (String) session.getAttribute(Constant.ERROR_MSG_KEY);
        if (StrUtil.isNotBlank(errorMsg)){
            session.removeAttribute(Constant.ERROR_MSG_KEY);
            return buildSuccessRest(errorMsg);
        }else {
            return buildSuccessRest(Constant.NO_ERROR_MSG);
        }
    }


}
